package com.keyroy.game.puzzle_rpg.views;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.widgets.Composite;

import com.keyroy.game.puzzle_rpg.models.render.MapRender;
import com.keyroy.game.puzzle_rpg.models.world.Map;

public class MapEditView extends Composite {
	private Map map;
	private MapRender mapRender;

	public MapEditView(Composite parent, Map map) {
		super(parent, SWT.BORDER | SWT.DOUBLE_BUFFERED);

		addPaintListener(new PaintListener() {

			@Override
			public void paintControl(PaintEvent event) {
				if (mapRender != null) {
					mapRender.onDraw(event.gc);
				}
			}
		});
		setMap(map);
	}

	public void setMap(Map map) {
		this.map = map;
		if (this.map != null) {
			this.mapRender = new MapRender(this.map);
			Object image = mapRender.getImage(this.map.icon);
			setSize(mapRender.imageWidth(image),mapRender.imageHeight(image));
		}
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

}
